""" 遍历当目录和子目录下的头文件，从头文件中获取类名，成员变量以及成员变量的类型，成员函数以及成员函数的参数和返回值 """
import os
import re

def get_class_name(content):
    """ 获取类名 """
    class_name = re.findall(r"class\s+(\w+)\s*:", content)
    class_name2 = re.findall(r"class\s+(\w+)\s*:\s*\w+\s+\w+", content)
    return class_name

def get_class_parent(content):
    """ 获取父类 """
    parent_class_name = re.findall(r"class\s+(\w+)\s*:\s*\w+\s+\w+", content)
    return parent_class_name

def get_class_parent_type(content):
    """ 获取继承方式 """
    class_parent_type = re.findall(r"class\s+\w+\s*:\s*(\w+)\s+\w+", content)
    return class_parent_type

def get_private_members(content):
    """ 获取私有成员变量 """
    private_members = re.findall(r"private:\s*(\w+\s+\w+;)", content)
    return private_members

def get_public_methods(content):
    """ 获取共有成员函数 """
    public_methods = re.findall(r"public:\s*(\w+\s+\w+\(.*\);)", content)
    return public_methods

def get_members_type(content):
    """ 获取成员变量的类型 """
    members_type = re.findall(r"(\w+)\s+\w+;", content)
    return members_type

def get_methods_params(content):
    """ 获取成员函数的参数 """
    methods_params = re.findall(r"\w+\s+\w+\((.*)\);", content)
    return methods_params

def get_methods_return(content):
    """ 获取成员函数的返回值 """
    methods_return = re.findall(r"\w+\s+(\w+)\s*\(", content)
    return methods_return

def get_methods_params_type(content):
    """ 获取成员函数的参数类型 """
    methods_params_type = re.findall(r"(\w+)\s+\w+", content)
    return methods_params_type

def get_methods_params_name(content):
    """ 获取成员函数的参数名 """
    methods_params_name = re.findall(r"\w+\s+(\w+)", content)
    return methods_params_name

def get_methods_return_type(content):
    """ 获取成员函数的返回值类型 """
    methods_return_type = re.findall(r"(\w+)\s+\w+\s*\(", content)
    return methods_return_type

def get_all_files(path):
    """ 获取当前目录和子目录下的所有文件 """
    all_files = []
    for root, dirs, files in os.walk(path):
        for file in files:
            all_files.append(os.path.join(root, file))
    return all_files

def get_header_files(path):
    """ 获取当前目录和子目录下的所有头文件 """
    header_files = []
    for file in get_all_files(path):
        if os.path.splitext(file)[1] == '.h':
            header_files.append(file)
    return header_files

def get_cpp_files(path):
    """ 获取当前目录和子目录下的所有源文件 """
    cpp_files = []
    for file in get_all_files(path):
        if os.path.splitext(file)[1] == '.cpp':
            cpp_files.append(file)
    return cpp_files

def get_class_name_from_header_file(file):
    """ 从头文件中获取类名 """
    with open(file, "r") as f:
        content = f.read()
        class_name = get_class_name(content)
        return class_name

def get_private_members_from_header_file(file):
    """ 从头文件中获取私有成员变量 """
    with open(file, "r") as f:
        content = f.read()
        private_members = get_private_members(content)
        return private_members
    
def get_public_methods_from_header_file(file):
    """ 从头文件中获取共有成员函数 """
    with open(file, "r") as f:
        content = f.read()
        public_methods = get_public_methods(content)
        return public_methods

def get_members_type_from_header_file(file):
    """ 从头文件中获取成员变量的类型 """
    with open(file, "r") as f:
        content = f.read()
        members_type = get_members_type(content)
        return members_type

def get_methods_params_from_header_file(file):
    """ 从头文件中获取成员函数的参数 """
    with open(file, "r") as f:
        content = f.read()
        methods_params = get_methods_params(content)
        return methods_params

def get_methods_return_from_header_file(file):
    """ 从头文件中获取成员函数的返回值 """
    with open(file, "r") as f:
        content = f.read()
        methods_return = get_methods_return(content)
        return methods_return

def get_methods_params_type_from_header_file(file):
    """ 从头文件中获取成员函数的参数类型 """
    with open(file, "r") as f:
        content = f.read()
        methods_params_type = get_methods_params_type(content)
        return methods_params_type

def get_methods_params_name_from_header_file(file):
    """ 从头文件中获取成员函数的参数名 """
    with open(file, "r") as f:
        content = f.read()
        methods_params_name = get_methods_params_name(content)
        return methods_params_name

def get_methods_return_type_from_header_file(file):
    """ 从头文件中获取成员函数的返回值类型 """
    with open(file, "r") as f:
        content = f.read()
        methods_return_type = get_methods_return_type(content)
        return methods_return_type


if __name__ == '__main__':
    path = os.getcwd()
    header_files = get_header_files(path)
    cpp_files = get_cpp_files(path)
    for file in header_files:
        class_name = get_class_name_from_header_file(file)
        parent_class_name = get_class_parent(file)
        parent_class_type = get_class_parent_type(file)
        private_members = get_private_members_from_header_file(file)
        public_methods = get_public_methods_from_header_file(file)
        members_type = get_members_type_from_header_file(file)
        methods_params = get_methods_params_from_header_file(file)
        methods_return = get_methods_return_from_header_file(file)
        methods_params_type = get_methods_params_type_from_header_file(file)
        methods_params_name = get_methods_params_name_from_header_file(file)
        methods_return_type = get_methods_return_type_from_header_file(file)
        print("类名：", class_name)
        print("父类名：", parent_class_name)
        print("父类类型：", parent_class_type)
        print("私有成员变量：", private_members)
        print("共有成员函数：", public_methods)
        print("成员变量的类型：", members_type)
        print("成员函数的参数：", methods_params)
        print("成员函数的返回值：", methods_return)
        print("成员函数的参数类型：", methods_params_type)
        print("成员函数的参数名：", methods_params_name)
        print("成员函数的返回值类型：", methods_return_type)
        

